package com.star.modules.sys.service;

import com.jeesite.common.entity.Page;
import com.jeesite.common.mapper.BeanMapper;
import com.jeesite.modules.sys.utils.DictUtils;
import com.star.modules.sys.base.BizDataResult;
import com.star.modules.sys.entity.ShHouse;
import com.star.modules.sys.enums.DictEnum;
import com.star.modules.sys.enums.ResultEnum;
import com.star.modules.sys.excetion.ApiException;
import com.star.modules.sys.vo.HouseDetailVo;
import com.star.modules.sys.vo.HouseDictVo;
import com.star.modules.sys.vo.IndexVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 首页服务类
 */
@Service
@Transactional(readOnly = true)
public class GlodHouseService {

    @Autowired
    private ShHouseService shHouseService;
    /**
     * 底部动态信息
     * @return
     */
    public BizDataResult getHouseDict() {
        HouseDictVo houseDictVo = new HouseDictVo();
        try {
            houseDictVo.setCurrentStatus(BeanMapper.mapList(DictUtils.getDictList(DictEnum.CURRENT_STATUS.getCode())
                    ,HouseDictVo.HouseCondition.class));
            houseDictVo.setAreaCondition(BeanMapper.mapList(DictUtils.getDictList(DictEnum.AREA_CONDITION.getCode())
                    ,HouseDictVo.HouseCondition.class));
            houseDictVo.setPropertyType(BeanMapper.mapList(DictUtils.getDictList(DictEnum.PROPERTY_TYPE.getCode())
                    ,HouseDictVo.HouseCondition.class));
            houseDictVo.setUseCondition(BeanMapper.mapList(DictUtils.getDictList(DictEnum.USE_CONDITION.getCode())
                    ,HouseDictVo.HouseCondition.class));
        } catch (Exception e) {
            throw new ApiException(e);
        }
        return BizDataResult.createResult(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg(),houseDictVo);
    }

    /**
     * 获取房屋
     * @return
     */
    public BizDataResult getHouse(ShHouse shHouse ,Page page) {
        Page pages = null;
        try {
            shHouse.setStatus(ShHouse.STATUS_NORMAL);
            pages = shHouseService.findPage(page,shHouse);
            pages.setList(BeanMapper.mapList(pages.getList(),IndexVo.HouseVo.class));
        } catch (Exception e) {
            throw new ApiException(e);
        }
        return BizDataResult.createResult(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg(),pages);
    }

    /**
     * 详情面
     * @param id
     * @return
     */
    public BizDataResult getHouseDetail(String id) {
        HouseDetailVo vo = null;
        try {
            ShHouse shHouse = shHouseService.get(id);
            vo = BeanMapper.map(shHouse,HouseDetailVo.class);
            vo.setPropertyTypeStr(DictUtils.getDictLabel(DictEnum.PROPERTY_TYPE.getCode()
                    ,vo.getPropertyType()+"", IndexService.DEFAULT_LABEL));
            vo.setLandRightsStr(DictUtils.getDictLabel(DictEnum.LAND_RIGHTS.getCode()
                    ,vo.getLandRights()+"", IndexService.DEFAULT_LABEL));
            vo.setCurrentStatusStr(DictUtils.getDictLabel(DictEnum.CURRENT_STATUS.getCode()
                    ,vo.getCurrentStatus()+"", IndexService.DEFAULT_LABEL));
            vo.setBuildConstructionStr(DictUtils.getDictLabel(DictEnum.BUILD_CONSTRUCTION.getCode()
                    ,vo.getBuildConstruction()+"", IndexService.DEFAULT_LABEL));
            vo.setUseConditionStr(DictUtils.getDictLabel(DictEnum.USE_CONDITION.getCode()
                    ,vo.getUseCondition()+"", IndexService.DEFAULT_LABEL));
        } catch (Exception e) {
            throw new ApiException(e);
        }
        return BizDataResult.createResult(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg(),vo);
    }
}
